package cn.edu.demo.controller;

import cn.edu.demo.pojo.*;
import cn.edu.demo.pojo.result.LoginResult;
import cn.edu.demo.pojo.result.OrderlistResult;
import cn.edu.demo.pojo.result.SureResult;
import cn.edu.demo.service.CarService;
import cn.edu.demo.service.DriverService;
import cn.edu.demo.service.OrdersService;
import cn.edu.demo.service.PassengerService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
public class SureController {

//@RestController
//@CrossOrigin


        @Autowired
        OrdersService ordersService;
        @Autowired
        CarService carService;
        @Autowired
        DriverService driverService;

        @RequestMapping("/user/sure")
        @ResponseBody
        public ResponseResult orders(String o_id){
            List<OrdersWithBLOBs> sureList = ordersService.sure(o_id);
            List<SureResult> surelistResult = new ArrayList<>();

//            ObjectMapper objectMapper = new ObjectMapper();
            if(sureList!=null){
                for(OrdersWithBLOBs orders : sureList){
                    surelistResult.add(new SureResult(driverService.getDriver(orders.getDriverId()), carService.getCar(orders.getCarId()), orders));
                }
                return new ResponseResult(110,"确认成功",surelistResult);
            }else{
                return new ResponseResult(111,"确认失败",null);
            }
//        return null;
    }
}
